#include "system.h"
#include "assert.h"
#include "gdt.h"
#include "idt.h"
#include "irq.h"
#include "keyboard.h"
#include "timer.h"
/*#include "syscall.h"*/

void print_uptime(){
	char x = getx();
	char y = gety();
	gotoxy(60,24);
	puts("Uptime ");
	puti(uptime());
	puts("s");
	gotoxy(x,y);
}

void print_level(){
	unsigned short rcs;
	unsigned short rds;
	__asm__ ("mov %%cs, %0\n\t":: "m" (rcs));
	__asm__ ("mov %%ds, %0\n\t":: "m" (rds));
	puts("CPL = ");
	puti(rcs & 0x3);
	putc('\n');
	puts("RPL = ");
	puti(rds & 0x3);
	putc('\n');
}

void kmain( void* mbd, unsigned int magic )
{
	video_init();
puts("I'm hereee!!");
	gdt_init();
	idt_init();
	

	irq_install();
	keyboard_install();
	timer_install();
	/*syscalls_init();*/
	__asm__ __volatile__ ("sti"); 

	/*putc(1 / 0);*/
	/*settextcolor(COLOR_BLACK, COLOR_LIGHT_BROWN);
	puts("K-OS 0.1.2\n");
	settextcolor(COLOR_RED, COLOR_BLUE);
	puts("Yeah baby!\n");*/
	reg_timed_func(100,print_uptime);
	/*for(;;);*/
}

void ring3(){
	print_level();
	/*puts("I'm on ring 3");*/
	for(;;);
	__asm__ ("int $0x4D");
}

void loop(){
	puts("Going to loop\n");
	for (;;);
}

void msg(){
	puts("I'm here\n");
}
